
<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>留言板</title>
  <?php $name; ?>
    <!-- Bootstrap core CSS -->
    <link href="<?php echo __PUBLIC__; ?>/css/bootstrap.min.css" rel="stylesheet">

    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="jumbotron.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <script src="../../assets/js/ie-emulation-modes-warning.js"></script>

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://cdn.bootcss.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://cdn.bootcss.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>

  <body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
      <div class="container">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="./">留言板</a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">
          <form class="navbar-form navbar-right">
            <div class="form-group">
              <input type="text" placeholder="Email" class="form-control">
            </div>
            <div class="form-group">
              <input type="password" placeholder="Password" class="form-control">
            </div>
            <button type="submit" class="btn btn-success">Sign in</button>
          </form>
        </div><!--/.navbar-collapse -->
      </div>
    </nav>

    <!-- Main jumbotron for a primary marketing message or call to action -->
    <style type="text/css">
          .ok{
            color: #449D44;
          }
          .error{
            color: #D9534F;
          }
          .info{
            line-height: 30px;
          }


    </style>
    <div class="container" style="padding-top:100px;">
      <form action="./index.php?m=index&c=reg&a=add" class="form-horizontal" method="post">
        <div class="form-group">
          <label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
          <div class="col-sm-4">
            <input type="email" class="form-control checkdata" id="email" placeholder="邮箱" name="email">
          </div>
          <div class="info"></div>
          
        </div>
        <div class="form-group">
          <label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
          <div class="col-sm-4">
            <input type="text" class="form-control checkdata" id="username" placeholder="用户名" name="username">
          </div>
          <div class="info"></div>
        </div>
        <div class="form-group">
          <label for="inputEmail3" class="col-sm-2 control-label">手机</label>
          <div class="col-sm-4">
            <input type="text" class="form-control checkdata" id="inputEmail3" placeholder="手机" name="phone">
          </div>
          <div class="info"></div>
        </div>
        <div class="form-group">
          <label for="inputPassword3" class="col-sm-2 control-label">密码</label>
          <div class="col-sm-4">
            <input type="password" class="form-control checkdata" id="password" name="password" placeholder="密码">
          </div>
          <div class="info"></div>
        </div>
        <div class="form-group">
          <label for="inputPassword3" class="col-sm-2 control-label">确认密码</label>
          <div class="col-sm-4">
            <input type="password" class="form-control checkdata" id="inputPassword3" name="repassword" placeholder="确认密码">
          </div>
          <div class="info"></div>
        </div>
        <div class="form-group">
          <div class="col-sm-offset-2 col-sm-10">
            <button type="submit" class="btn-submit btn btn-success" disabled="">注册</button>
          </div>
        </div>
      </form>

      <hr>

      <footer>
        <p>&copy; 2016 Company, Inc.</p>
      </footer>
    </div> 
    <script src="https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js"></script>

    <script type="text/javascript">

        $(function  () {

          $('.checkdata').blur(function(event) {
              that = $(this);
              name = $(this).attr('name');
              data = $(this).val();

              if(name =='repassword'){
                  if(data==$('#password').val()){
                      that.parent().siblings('.info').removeClass('error').addClass('ok').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>'+"密码一致");
                      checkSubmit();
                  }else{
                      that.parent().siblings('.info').removeClass('ok').addClass('error').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>'+"两次密码不一致");
                      checkSubmit();
                  }
              }

              $.ajax({
                url: 'index.php?m=index&c=reg&a=checkdata',
                type: 'POST',
                dataType: 'json',
                data: {data: data,name:name},
              })
              .done(function(res) {
                if(res.error==1){
                  that.parent().siblings('.info').removeClass('ok').addClass('error').html('<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>'+res.info);
                  checkSubmit();
                }else{
                  that.parent().siblings('.info').removeClass('error').addClass('ok').html('<span class="glyphicon glyphicon-ok" aria-hidden="true"></span>'+res.info);
                  checkSubmit();
                }
              })
              .fail(function() {
                console.log("error");
              })
          });
        })
        
        function checkSubmit () {
            
            num = $('.glyphicon-ok').length;

            if(num==5){
                $('.btn-submit').attr('disabled',false);
            }else{
                $('.btn-submit').attr('disabled', true);
            }
        }
          
    </script>
    
  </body>
</html>
